﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.DynamicData.ModelProviders;
using Mpu.NHibernateDataModelProvider.AssociationProviders;

namespace Mpu.NHibernateDataModelProvider.ColumnProviders
{
    public class NHibernateManyToOneColumnProvider : NHibernateColumnProviderBase
    {
        private NHibernate.Mapping.Property property;
        private NHibernate.Mapping.Column column;

        public NHibernateManyToOneColumnProvider(TableProvider table, NHibernate.Mapping.Property property, NHibernate.Mapping.Column column)
            : base(table)
        {
            this.Name = property.Name;
            this.ColumnType = property.Type.ReturnedClass;

            this.property = property;
            this.column = column;
        }

        public string AssociatedTypeName
        {
            get
            {
                return property.Type.ReturnedClass.FullName;
            }
        }

        public override void Initialize()
        {
            base.Initialize();

            this.Association = new NHibernateManyToOneAssociationProvider(this, property, column);
        }
    }
}
